#!/bin/bash
#
set -x

source `dirname $0`/stackenv

timeout="60m"
failed=


if [[ -z $ACCEPTANCE_TESTS ]]; then
    echo "No acceptance tests to run"
    exit 0
fi

TESTS=($(python <<< "print(' '.join($ACCEPTANCE_TESTS))"))

for acceptance_test in "${TESTS[@]}"; do
  go test -v -timeout $timeout -tags "fixtures acceptance" ./${acceptance_test}
  # Check the error code after each suite, but do not exit early if a suite failed.
  if [[ $? != 0 ]]; then
    failed=1
  fi
done

# If any of the test suites failed, exit 1
if [[ -n $failed ]]; then
  exit 1
fi

exit 0
